<?php

namespace App\Models\Sys;

use Illuminate\Database\Eloquent\Model;

class AdsCategory extends Model
{
    protected $table = 'jxt_sys_ads_category';
    public $primaryKey = 'id';

    const CREATED_AT = 'created_at';
    const UPDATED_AT = null;

    protected static function boot()
    {
        static::deleting(function ($model) {

            $count = Ads::where('category_id', $model->id)->count();
            if ($count) {
                throw new \Exception('分类下有广告信息,不能直接删除！！');
            }
        });

        //parent::boot();
    }

    public static function options()
    {
        $options = static::select('id','name as text')->get();
        $selectOption = [];
        foreach ($options as $option){
            $selectOption[$option->id] = $option->text;
        }
        return $selectOption;
    }

}
